using System.Collections.Generic;
using System.Collections.ObjectModel;

namespace sql_train
{
    public class SimpleDataTable
    {
        public SimpleDataTable(IEnumerable<SimpleDataColumn> mColumns, IEnumerable<SimpleDataRow> mRows)
        {
            m_columns = new List<SimpleDataColumn>(mColumns);
            m_rows = new List<SimpleDataRow>(mRows);
        }

        public bool Equals(SimpleDataTable other)
        {
            if (ReferenceEquals(null, other)) return false;
            if (ReferenceEquals(this, other)) return true;
            return Utils.CollectionsEqual(other.m_columns, m_columns) && Utils.CollectionsEqual(other.m_rows, m_rows);
        }

        public override bool Equals(object obj)
        {
            if (ReferenceEquals(null, obj)) return false;
            if (ReferenceEquals(this, obj)) return true;
            if (obj.GetType() != typeof (SimpleDataTable)) return false;
            return Equals((SimpleDataTable) obj);
        }

        public override int GetHashCode()
        {
            unchecked
            {
                return (Utils.GetCollectionHashCode(m_columns)*397) ^ Utils.GetCollectionHashCode(m_rows);
            }
        }

        private readonly List<SimpleDataColumn> m_columns;
        public ReadOnlyCollection<SimpleDataColumn> Columns
        {
            get
            {
                return new ReadOnlyCollection<SimpleDataColumn>(m_columns);
            }
        }

        private readonly List<SimpleDataRow> m_rows;
        public ReadOnlyCollection<SimpleDataRow> Rows
        {
            get
            {
                return new ReadOnlyCollection<SimpleDataRow>(m_rows);
            }
        }
    }
}